package com.hksj.aqm.controller;

import com.hksj.aqm.dto.AqmLargeScreenDTO;
import com.hksj.aqm.service.AqmLargeScreenService;
import com.hksj.aqm.service.Pm25Service;
import com.hksj.aqm.vo.AqmAlarmTypeVO;
import com.hksj.base.query.AlarmQuery;
import com.hksj.common.core.model.Rest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Api(tags = "空气质量-报警接口")
@RequestMapping("/api/aqm/alarm")
@RestController
public class AqmAlarmController {
    @Autowired
    private Pm25Service pm25Service;
    @Autowired
    private AqmLargeScreenService aqmLargeScreenService;

    @ApiOperation("报警记录-导出")
    @PostMapping("/exportAlarm")
    public void exportAlarm(@RequestBody AlarmQuery query, HttpServletResponse response){
        pm25Service.exportAlarm(query,response);
    }

    @ApiOperation(value = "报警记录-报警次数")
    @PostMapping("/listPropertyAlarmNum")
    public Rest<List<AqmAlarmTypeVO>> listPropertyAlarmNum(@RequestBody AqmLargeScreenDTO dto){
        if (StringUtils.hasText(dto.getStartTime())){
            dto.setStartTime(dto.getStartTime().substring(0, 10) + " 00:00:00");
        }
        if (StringUtils.hasText(dto.getEndTime())){
            dto.setEndTime(dto.getEndTime().substring(0, 10) + " 23:59:59");
        }
        return Rest.ok(aqmLargeScreenService.queryAqmAlarmByType(dto));
    }
}
